;layui.define(function(e) {
    layui.use(['table','layer','form','laydate'], function(){
        var $ = layui.$
            ,layer = layui.layer
            ,form = layui.form
            ,table = layui.table
            ,laydate = layui.laydate;
        //展示已知数据
        table.render({
            elem: '#idTest'
            ,cols: [[ //标题栏
                {type:'checkbox', fixed: 'left'},
                {field: 'brand', title: '品牌'}
                ,{field: 'carSeries', title: '车系'}
                ,{field: 'carType', title: '车型', minWidth: 120}
                ,{field: 'guidePrice', title: '指导价(元)', sort: true}
                ,{field: 'purchasePrice', title: '采购价(元)', sort: true}
                ,{field: 'closePrice', title: '批售价(元)', sort: true}
                ,{field: 'payment', title: '支付方式'}
                ,{field: 'area', title: '销售区域'}
                ,{field: 'arrivalPeriod', title: '到货周期(天)',sort: true}
                ,{field: 'minimum', title: '起订数量(辆)',sort: true}
                ,{field: 'inventory', title: '库存数量(辆)',sort: true}
                ,{field: 'date', title: '发布时间',minWidth: 120}
                ,{field: 'status', title: '车源状态'}
                ,{field: 'tool',title: '操作',fixed: 'right', minWidth:158, align:'center', toolbar: '#barDemo'}
            ]]
            ,height: 'full-400'
            ,cellMinWidth: 120
            ,data: [{
                "brand": "10001"
                ,"carSeries": "杜甫"
                ,"carType": "xianxin@layui.com"
                ,"guidePrice": "男"
                ,"purchasePrice": "浙江杭州"
                ,"closePrice": "人生恰似一场修行"
                ,"payment": "116"
                ,"area": "192.168.0.8"
                ,"arrivalPeriod": "108"
                ,"minimum": "2016-10-14"
                ,"inventory": "192.168.0.8"
                ,"date": "108"
                ,"status": "2016-10-14"
                ,"tool": "2016-10-14"
            }]
            ,page: true //是否显示分页
        });
        //监听新增按钮

        //监听表格复选框选择
        table.on('checkbox(listTable)', function(obj){
            console.log(obj)
        });
        //监听工具条
        table.on('tool(listTable)', function(obj){
            var data = obj.data;
            if(obj.event === 'detail'){
                var index = layer.open({
                    type: 2
                    ,id: (new Date()).valueOf()
                    ,title: '详情'
                    ,content: 'detail.html'
                    ,area: ['500px', '500px']
                    ,btn: ['确定', '取消']
                    ,maxmin: true
                    ,success: function(layero, index){
                        var body = layer.getChildFrame('body', index);
                        var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
//                        console.log(body.html()) //得到iframe页的body内容
                        var paramId=body.find("input[name='id']");
                        paramId.val(111);
                    }
                    ,yes: function (layero, index) {
                        layer.alert("确定按钮");
                        return false //开启该代码可禁止点击该按钮关闭
                    }
                    ,btn2: function (layero, index) {
                        layer.alert("取消按钮")
                        //return false 开启该代码可禁止点击该按钮关闭
                    }
                });
                layer.full(index);
            } else if(obj.event === 'soldOutShlef'){
                layer.confirm('确定下架吗?', function(index){
                    obj.del();
                    layer.close(index);
                });
            } else if(obj.event === 'putOnShelf'){
                layui.alert("上架")
            }else if(obj.event === 'edit'){
                var index = layer.open({
                    type: 2
                    ,id: (new Date()).valueOf()
                    ,title: '编辑'
                    ,content: 'inputOptions.html'
                    ,area: ['500px', '500px']
                    ,btn: ['确定', '取消']
                    ,maxmin: true
                    ,success: function(layero, index){
                        var body = layer.getChildFrame('body', index);
                        var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
//                        console.log(body.html()) //得到iframe页的body内容
                        var paramId=body.find("input[name='id']");
                        paramId.val(111);
                    }
                    ,yes: function (layero, index) {
                        layer.alert("确定按钮");
                        //return false 开启该代码可禁止点击该按钮关闭
                    }
                    ,btn2: function (layero, index) {
                        layer.alert("取消按钮")
                        //return false 开启该代码可禁止点击该按钮关闭
                    }
                });
                layer.full(index);
            }
        });

        var $ = layui.$, active = {
            getCheckData: function(){ //获取选中数据
                var checkStatus = table.checkStatus('idTest')
                    ,data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            }
            ,getCheckLength: function(){ //获取选中数目
                var checkStatus = table.checkStatus('idTest')
                    ,data = checkStatus.data;
                layer.msg('选中了：'+ data.length + ' 个');
            }
            ,isAll: function(){ //验证是否全选
                var checkStatus = table.checkStatus('idTest');
                layer.msg(checkStatus.isAll ? '全选': '未全选')
            }
        };

        $('.layadmin-takerates .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        //执行一个laydate实例
        laydate.render({
            elem: '#date'
        });
        form.render();
        $("#inputOptions").click(function () {
            var index = layer.open({
                type: 2
                ,id: (new Date()).valueOf()
                ,title: '录入车源'
                ,content: 'inputOptions.html'
                ,area: ['500px', '500px']
                ,btn: ['发布','保存', '取消']
                ,skin:'my_skin'
                ,maxmin: true
//                 ,success: function(layero, index){
//                     var body = layer.getChildFrame('body', index);
//                     var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
// //                        console.log(body.html()) //得到iframe页的body内容
//                     var paramId=body.find("input[name='id']");
//                     paramId.val(111);
//                 }
                ,yes: function(index, layero){
                    alert("发布")
                    //发布【按钮一】的回调
                }
                ,btn2: function(index, layero){
                    //保存【按钮二】的回调
                    // alert("保存")
                    var body = layer.getChildFrame('body', index);
                    var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
//                        console.log(body.html()) //得到iframe页的body内容
                    var paramId=body.find("input[name='guidePrice']");
                    // paramId.val();
                    alert(paramId.val())
                    return false //开启该代码可禁止点击该按钮关闭
                }
                ,btn3: function(index, layero){
                    //取消【按钮三】的回调
                    alert("取消")
                    //return false 开启该代码可禁止点击该按钮关闭
                }
            });
            layer.full(index);
        })
        $(".check_more").click(function () {
            var index = layer.tab({
                type: 2
                ,id: (new Date()).valueOf()
                ,title: '更多参数配置'
                ,content: 'more.html'
                ,area: ['500px', '700px']
                ,maxmin: true
//                 ,success: function(layero, index){
//                     弹框加载成功页面参数传递给弹框
//                     var body = layer.getChildFrame('body', index);
//                     var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
// //                        console.log(body.html()) //得到iframe页的body内容
//                     var paramId=body.find("input[name='id']");
//                     paramId.val(111);
//                 }
            });
            layer.full(index);
        })
    });
    //输出模块
    e("list", {})
});